/**
 * Created by renzhiqiang on 18/7/4.
 */
import React from 'react';
import { connect } from 'dva';
import {Popconfirm,Modal} from 'antd';
import { routerRedux } from 'dva/router';
import {CFFTableView} from './../../public/components/';
import {FFTitle,FFButtons,FFSearchs,FFTableView} from './../../public/business/index';
import './index.less';
import {openModal,getUrlParam} from "./../../public/utils/index"

function <%=router%>({dispatch, <%=router%>}) {
    const {pageParam,list,total,loading,configPage} = <%=router%>;
    const actionTypeHead= "<%=router%>/";

    // 按钮组参数
    const Buttons = {
        ele:configPage.buttonInfo||[],
        clickFn(ele,data){ //
            console.info(ele,data);
            // dispatch(routerRedux.push('/add/'+getUrlParam(1)+"/"+getUrlParam(0)));
        }
    };
    // 按钮组参数
    const Searchs = {
        ele:configPage.searchInfo||[],
        clickFn(data){
            dispatch({
                type: '<%=router%>/fetch',
                payload: {filterData:data}
            });
        }
    };
    // 表格配置参数
    const tableViewProps = {
        columns: configPage.tableHeads||[],
        operations:configPage.operations,
        //操作(编辑,删除)回调
        operationCb: function (config, data) {
            console.info(config, data)
        },
        dataSource: list,
        total: total,
        loading: loading,
        pageParam: {
            current: pageParam.pageNo,
            pageSize: pageParam.pageSize,
            // 一页数量
            onShowSizeChange: (current, pageSize) => {
                dispatch({
                    type: actionTypeHead + 'fetch',
                    payload: {
                        pageParam: {
                            pageNo: 1,
                            pageSize: pageSize,
                            keyword: ''
                        }
                    }
                });
            },
            // 翻页
            onChange: (current) => {
                dispatch({
                    type: actionTypeHead + 'fetch',
                    payload: {
                        pageParam: {
                            ...pageParam,
                            pageNo: current,
                        },
                    }
                });
            },
            //排序回调 需要对应columns中, 开启sorter:true
            sortParamChange(pagination, filters, sorter) {
                if (sorter.field) {
                    dispatch({
                        type: actionTypeHead + 'setFilterParam',
                        payload: {
                            order: sorter.order,
                            field: sorter.field,
                            type: 'sort'
                        }
                    });
                }
            },
            //搜索关键字
            onSearch (value) {
                dispatch({
                    type: actionTypeHead + 'fetch',
                    payload: {
                        pageParam: {
                            ...pageParam,
                            pageNo: 1,
                            keyword: value
                        }
                    }
                })
            }
        }
    };
    return (
        <div className='<%=router%>'>
            <FFTitle name="当前位置：系统管理>菜单管理"/>
            <FFButtons {...Buttons}/>
            <FFSearchs {...Searchs}/>
            <FFTableView {...tableViewProps}/>
        </div>
    );
}

function mapStateToProps({<%=router%>}) {
    return {<%=router%>};
}
export default connect(mapStateToProps)(<%=router%>);
